﻿using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.IO;
public class SGUIConfig
{
   static string configPath = Application.streamingAssetsPath ;
   static Dictionary<string, string> configValues; 
   public static string Get(string key)
   {
       if (configValues == null) 
       {
           LoadConfig();
       }
       if (configValues.ContainsKey(key)) 
       {
        return configValues[key];
       }
       return string.Empty;
   }

   public static void LoadConfig() 
   {
       configValues = new Dictionary<string, string>();
       if (!File.Exists(configPath + "/SGUIConfig.txt")) 
       {
           File.CreateText(configPath+"/SGUIConfig.txt").Close();
       }
       string configTxt = File.ReadAllText(configPath + "/SGUIConfig.txt");
       string[] allConfigLine = configTxt.Split('\n');
       for (int i = 0; i < allConfigLine.Length;i++)
       {
          string lineStr = allConfigLine[i].Trim().Trim('\r');
          string[] linekv = lineStr.Split('=');
          if (linekv.Length == 2) 
          {
              configValues.Add(linekv[0].Trim(),linekv[1].Trim());
          }
       }

   }
}
